package com.guoliang.commonUtils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author ：Leo
 * @date ：Created in 2023/1/13 12:39
 * @description：
 */
@Data
public class CommonResult {
   @ApiModelProperty(value = "是否成功")
   private Boolean success;
   @ApiModelProperty(value = "状态码")
   private Integer code;
   @ApiModelProperty(value = "返回消息")
   private String message;
   @ApiModelProperty(value = "返回数据")
   private Map<String, Object> data=new HashMap<>();

   private CommonResult(){};

   //成功静态方法
    public static CommonResult ok(){
        CommonResult commonResult=new CommonResult();
        commonResult.setSuccess(true);
        commonResult.setCode(ResultCode.SUCCESS);
        commonResult.setMessage("成功");
        return commonResult;
    }
    //失败静态方法
    public static CommonResult error(){
        CommonResult commonResult=new CommonResult();
        commonResult.setSuccess(false);
        commonResult.setCode(ResultCode.ERROR);
        commonResult.setMessage("失败");
        return commonResult;
    }
    public CommonResult success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public CommonResult code(Integer code){
        this.setCode(code);
        return this;
    }
    public CommonResult message(String message){
        this.setMessage(message);
        return this;
    }
    public CommonResult date(Map<String,Object> data){
        this.setData(data);
        return this;
    }
    public CommonResult data(String key,Object value){
        this.data.put(key, value);
        return this;
    }
}
